<template>
  <div>
    <!--<div class="commit">未知的甜 等待你去探索</div>-->
  </div>
</template>

<script type="text/ecmascript-6">
  import Public from '@/assets/js/public';
  import Props from '@/assets/js/Props';
  import SloganPanel from '../../components/common/SloganPanel';
  import BtnPrimary from '../../components/common/BtnPrimary';
  import BackgroundImg from '../../components/login/BackgroundImg';
  import Types from '@/store/OperationType';
  import Load from '../../components/common/load/load';
  // import Vconsole from 'vconsole';

  export default {
    /** kebab-case */
    name: 'wx-login',

    data() {
      return {
        loading: false,
        aaa: {},
        bhb: '', // oid
        bg: '', // recuser
        ani: false,
        anim: false,
        opc: false,
        opa: false
      };
    },
    /** 在声明 prop 的时候，其命名应该始终使用 camelCase，而在模板和 JSX 中应该始终使用 kebab-case。
     String/Number/Boolean/Function/Object/Array/Symbol */
    props: {},

    components: {Load, BackgroundImg, BtnPrimary, SloganPanel},

    methods: {
      getIcon(icon) {
        return Public.ossImg + icon + '.svg';
      },
      GetQueryString(name) {
        let reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
        let r = window.location.search.substr(1).match(reg);
        if (r !== null) return unescape(r[2]);
        return null;
      },
      commit() {
        this.loading = true;
        this.$store.commit(Types.SET_USER_OID, this.bhb);
        this.$Sale.login(this.aaa)
          .then(res => {
            /**
             * 先赋值用户权限
             * */
            let get = res.data;
            if (parseInt(get.uid) > 0) {
              // ROLE
              // this.$store.commit(Types.SET_LOGIN_STATE, LoginTypes.LOGIN);
              // todo 保存用户信息
              this.$store.commit(Types.SET_USER_REC, get.rec);
              this.$store.commit(Types.SET_USER_UID, get.uid);
              // this.$store.commit(Types.SET_USER_IS_BIND_PHONE, res.isBindPhone);
              // this.$store.commit(Types.SET_USER_IS_BUY, res.is_buy);
              this.$store.commit(Types.SET_USER_NAME, get.nick);
              this.$store.commit(Types.SET_USER_PIC, get.img);
              this.$store.commit(Types.SET_USER_PROVINCE, get.rank.level);
              this.$store.commit(Types.SET_USER_LEVEL, get.rank.levelCh);
              this.$store.commit(Types.SET_USER_AREA, get.area);
            } else {
              this.$store.commit(Types.SET_USER_UID, '0');
            }
            // if (typeof res.needBindPhone !== 'undefined') {
            //   this.$store.commit(Types.SET_USER_NEED_BIND_PHONE, res.needBindPhone);
            // }
            this.loading = false;
            this.$router.push({name: 'front'});
          }, () => {
            this.loading = false;
          });
      }
    },
    computed: {
      welcomeTxt() {
        return Props.PROJECT_NAME + '系统商城';
      }
    },
    watch: {
      // 监听具体数据变化，并做相应的处理
    },
    beforeCreate() {
      localStorage.clear();
    },
    created() {
    },
    mounted() {
      this.aaa = this.$route.query;
      this.commit();
      // if (this.oid === 'owAxr1lziZo5LZmu6mP8Hiy5Shro') {
      //   let vConsole = new Vconsole();
      //   Vue.prototype.$vConsole = vConsole;
      // }
    }
  };
</script>

<style lang="stylus" rel="stylesheet/stylus" scoped>
  @import "../../assets/stylus/main.styl";

</style>
